package org.logistics.main;

import org.logistics.CarListActivity;
import org.logistics.MainMapActivity;
import org.logistics.MapKeyPermission;
import org.logistics.R;
import org.logistics.bean.ActivityMangager;

import android.os.Bundle;
import android.app.ActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

public class LoginMainActivity extends TabActivity implements 
OnCheckedChangeListener {
	
	//选择导航栏
	public TabHost tabHost ; 
	//选择组
	private RadioGroup radioGroup;
	
	//账号
	private String userAccount;
	//定位中心号
	private int centerNum;
	
	
	protected void onCreate(Bundle savedInstanceState) {
		ActivityMangager.addActivity(this);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login_main);
		
		/**
		 * 判断网络状态
		 */
		MapKeyPermission net = new MapKeyPermission();
		boolean isNet = net.checkNetError(getApplicationContext());
		if(isNet == false){
			Toast.makeText(getApplicationContext(), "网络未连接，请先连接网络",
			            		     Toast.LENGTH_SHORT).show();
		}
		
		
		//获取账号信息 定位中心
		Intent intent = new Intent();
		intent = getIntent();
		userAccount = intent.getStringExtra("userAccount");
		centerNum = intent.getIntExtra("centerNum", 0);
		
		tabHost = getTabHost();
		
		tabHost.addTab(tabHost.newTabSpec("map").setIndicator("map").
				setContent(
						new Intent (this , MainMapActivity.class)
						.putExtra("userAccount", userAccount)
						.putExtra("centerNum", centerNum)));
		tabHost.addTab(tabHost.newTabSpec("list").setIndicator("list").
				setContent(new Intent (this , CarListActivity.class)
				.putExtra("userAccount", userAccount)));
//		tabHost.addTab(tabHost.newTabSpec("help").setIndicator("help").
//				setContent(new Intent (this , MainMapActivity.class)));
		
		radioGroup =  (RadioGroup) findViewById(R.id.main_radio);
		radioGroup.setOnCheckedChangeListener(this);
		
	}
	

	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login_main, menu);
		return true;
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) {
		case R.id.map:
			tabHost.setCurrentTabByTag("map");
			break;
		case R.id.list:
			tabHost.setCurrentTabByTag("list");
			break;
		case R.id.help:
			tabHost.setCurrentTabByTag("help");
			break;
		case R.id.local:
			tabHost.setCurrentTabByTag("local");
			break;
		case R.id.project:
			tabHost.setCurrentTabByTag("project");
			break;
		default:
			tabHost.setCurrentTabByTag("map");
		}
		
	}
	
	/**
	 * 回调处理函数
	 */
	@Override  
	protected void onDestroy(){  
	        super.onDestroy();  
	}  
	@Override  
	protected void onPause(){  
	        super.onPause();  
	}  

}
